<template>
	<view class="container">
		<div class="poster" :style="'background: ' + hdInfo.color + ' url(' + hdInfo.img + ') center top / 100%  no-repeat'">
			<div class="checkLogin">
				<u-button type="primary" shape="circle" text="进入活动" @click="toWebview"></u-button>
			</div>
		</div>

	</view>
</template>

<script>
export default {
	name: 'headcomd',
	data() {
		return {
			name:"",
			path: "",
			hdInfo: {
				link: '',
				img: '',
				color: ''
			}
		};
	},
	onShareAppMessage(options) {},
	onLoad(options) {
		if (!options) {
			this.infoScene = 'default';
		} else {
			this.name = options.name ? options.name : '强国';
			this.path = options.path
		}
	},
	computed: {
		userphone() {
			return this.$store.getters.userphone ? this.$store.getters.userphone : '';
		},
	},
	mounted() {
		this.getInfo()
		if (this.userphone) {
			this.singleRegister()
		}
	},
	watch: {
		userphone(val){
			if (this.userphone) {
				this.singleRegister()
			}
		}
	},
	created() {
		let that = this;
		
	},
	methods: {
		getInfo(){
			let that = this
			let l = 'https://www.baixuemianshi.com/zhuanti/webview/' + that.path + '/index.js'
			
			uni.request({
			    url: l,
			    method: 'get',
			    dataType: 'text',
			    data: { sstimes: new Date()},
			    success: function (res) {
			        var resjson = JSON.parse(res.data);
					
			        that.hdInfo = resjson
					console.log(that.hdInfo)
					
			    }
			})
		},
		singleRegister(){
			let that = this
			db.collection(that.path).add({
				data:{
					phone: that.userphone,
					remark: that.path
				},
				success:res =>{
					console.log(res)
				}
			})
		},
		toWebview() {
			let that = this;
			if(that.userphone){
				uni.navigateTo({
					url: '../../webview/index?href=' + encodeURIComponent(that.hdInfo.link + '?name=' + that.name)
				});
			}else{
				uni.navigateTo({
					url: '../../my/login?navTlt=' + encodeURIComponent(that.path + '?name=' + that.name)
				});
			}
			
		},
		
	}
};
</script>

<style>
.poster {
	position: fixed;
	top: 0;
	left: 0;
	width: 100%;
	height: 100vh;
	z-index: 9999;
	background-size: 100%;
}
.poster .checkLogin {
	position: absolute;
	bottom: 150rpx;
	left: 50%;
	width: 40%;
	transform: translateX(-50%);
}

</style>
